package com.iknow.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.file.CacheSystem;
import com.iknow.task.CommonTask.DownloadFileTask;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import java.io.File;

public class ImageZoomActivity extends Activity
{
  private View.OnClickListener SaveButtonClickListener;
  private View.OnClickListener ShareButtonClickListener;
  private CommonTask.DownloadFileTask mImageTask;
  private String mImageUrl;
  private WebView mImageView;
  private View mLoadingView;
  private Button mSaveButton;
  private Button mShareButton;
  private TaskListener mTaskListener;

  public ImageZoomActivity()
  {
    this.ShareButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        File localFile = new File(IKnow.mCacheSystem.getImageFileName(ImageZoomActivity.access$0(this.this$0)));
        if (localFile.exists())
        {
          Intent localIntent = new Intent("android.intent.action.SEND");
          localIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(localFile));
          localIntent.setType("image/jpeg");
          this.this$0.startActivity(Intent.createChooser(localIntent, "iKnow图片分享"));
        }
      }
    };
    this.SaveButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        String str = IKnow.mCacheSystem.getImageFileName(ImageZoomActivity.access$0(this.this$0));
        if (new File(str).exists())
          Toast.makeText(this.this$0, "图片保存在" + str, 0).show();
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "DownloadFileTask";
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        ImageZoomActivity.access$1(this.this$0).setVisibility(8);
        ImageZoomActivity.access$2(this.this$0);
      }

      public void onPreExecute()
      {
        ImageZoomActivity.access$1(this.this$0).setVisibility(0);
      }
    };
  }

  private void getImage()
  {
    if (!(loadImage()))
    {
      this.mImageTask = new CommonTask.DownloadFileTask();
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("url", this.mImageUrl);
      localTaskParams.put("file_name", IKnow.mCacheSystem.getImageFileName(this.mImageUrl));
      this.mImageTask.setListener(this.mTaskListener);
      CommonTask.DownloadFileTask localDownloadFileTask = this.mImageTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localDownloadFileTask.execute(arrayOfTaskParams);
    }
  }

  private void initView()
  {
    setContentView(2130903075);
    this.mImageView = ((WebView)findViewById(2131296407));
    this.mLoadingView = findViewById(2131296408);
    this.mSaveButton = ((Button)findViewById(2131296405));
    this.mSaveButton.setOnClickListener(this.SaveButtonClickListener);
    this.mShareButton = ((Button)findViewById(2131296406));
    this.mShareButton.setOnClickListener(this.ShareButtonClickListener);
  }

  private boolean loadImage()
  {
    int i;
    String str = IKnow.mCacheSystem.getImageFileName(this.mImageUrl);
    if (new File(str).exists())
    {
      this.mImageView.setVisibility(0);
      this.mImageView.loadUrl("file://" + str);
      this.mImageView.getSettings().setBuiltInZoomControls(true);
      i = 1;
    }
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    this.mImageUrl = getIntent().getStringExtra("imageUrl");
    initView();
    getImage();
  }
}